package com.service.impl;

import com.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.service.UserService;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * <bean id="userService" class="UserServiceImpl">
 *         <property name="userDao" ref="userDao"></property>
 *     </bean>
 */

@Service("userService")
@Scope("singleton")
public class UserServiceImpl implements UserService {

    @Autowired  //按照数据类型从spring容器中注入
    @Qualifier("userDao")   //按照id名称从容器中进行匹配，但是要结合@Autowired使用
    //@Resource(name="userDao")     @Resource相当于@Autowired+@Qualifier
    private UserDao userDao;

//采用注解方法可以不写，采用xml方式必须写
//    public UserDao getUserDao() {
//        return userDao;
//    }
//
//    public void setUserDao(UserDao userDao) {
//        this.userDao = userDao;
//    }
    @PostConstruct
    public void init(){
        System.out.println("初始化方法");
    }
@PreDestroy
    public void destory(){
        System.out.println("销毁方法");
    }
    @Value("${jdbc.driver}")
    private String driver;
    public void save() {
        System.out.println(driver);
        System.out.println("addd");
    }
}
